package com.weme.common.manager

import dev.kratos.api.user_server.v1.GetGiftListReply
import dev.kratos.api.user_server.v1.GiftInfo

object  GetGiftListReplyManager {

     var giftListReply: GetGiftListReply? = null

    // 保存 GetGiftListReply 对象
    fun saveGiftListReply(reply: GetGiftListReply) {
        this.giftListReply = reply
    }


    // 获取所有礼物列表
    fun getAllGifts(): List<GiftInfo> {
        return giftListReply?.giftListList ?: emptyList()
    }

    // 通过 ID 获取礼物
    fun getGiftById(id: Int): GiftInfo? {
        return giftListReply?.giftListList?.find { it.id == id }
    }

    // 删除礼物
    fun removeGiftById(id: Int) {
        giftListReply = giftListReply?.let { reply ->
            val updatedList = reply.giftListList.filter { it.id != id }
            reply.toBuilder().clearGiftList().addAllGiftList(updatedList).build()
        }
    }

    // 清空礼物列表
    fun clearGiftList() {
        giftListReply = giftListReply?.toBuilder()?.clearGiftList()?.build()
    }
}
